﻿
Imports System.IO.Path
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AllowDrop = True
        Me.TopMost = True
        NotifyIcon1.Visible = False
        NotifyIcon1.ContextMenuStrip = ContextMenuStrip1
        
    End Sub











    Dim fistw


    Private Sub Form1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
            For Each s As String In filePaths


                Dim sFile As String = IO.Path.GetFileName(s)
                Dim sExt As String = IO.Path.GetExtension(s)


                If sExt = ".exe" Then
                    Dim p As New System.Diagnostics.Process()
                    p.StartInfo.FileName = s

                    p.Start()
                    For Each Process As Process In Process.GetProcessesByName(sFile.Replace(".exe", ""))
                        Process.PriorityClass = ProcessPriorityClass.RealTime 'oder .high usw.
                    Next
                    Me.Hide()
                    NotifyIcon1.Visible = True
                    NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
                    NotifyIcon1.BalloonTipTitle = "Warnung! Prozess ist RealTime!"
                    NotifyIcon1.BalloonTipText = ("Das Programm " & sFile & " ist mit RealTime Gestartet!")
                    NotifyIcon1.ShowBalloonTip(250000)
                    fistw = sFile.Replace(".exe", "")
                    Timer1.Start()
                End If

                If sExt = ".lnk" Then

                    Dim p As New System.Diagnostics.Process()
                    p.StartInfo.FileName = LeseShellLinkPath(s)

                    p.Start()
                    For Each Process As Process In Process.GetProcessesByName(IO.Path.GetFileName(LeseShellLinkPath(s).Replace(".exe", "")))
                        Process.PriorityClass = ProcessPriorityClass.RealTime 'oder .high usw.
                    Next
                    Me.Hide()

                    NotifyIcon1.Visible = True
                    NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
                    NotifyIcon1.BalloonTipTitle = "Warnung! Prozess ist RealTime!"
                    NotifyIcon1.BalloonTipText = ("Das Programm " & IO.Path.GetFileName(LeseShellLinkPath(s) & " ist mit RealTime Gestartet!"))
                    NotifyIcon1.ShowBalloonTip(250000)

                    fistw = IO.Path.GetFileName(LeseShellLinkPath(s).Replace(".exe", ""))
                    Timer1.Start()

                End If









            Next s
        End If
    End Sub

    Private Sub Form1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub


    Public Function LeseShellLinkPath(ByVal datei As String) As String

        Dim oShell As New Shell32.Shell
        Dim oFolder As Shell32.Folder
        Dim oLink As Shell32.ShellLinkObject

        Dim sPath As String
        Dim sFile As String

        Dim sLinkFile As String = datei

        sPath = Strings.Left(sLinkFile, InStrRev(sLinkFile, "\") - 1)
        sFile = Mid$(sLinkFile, InStrRev(sLinkFile, "\") + 1)

        oFolder = oShell.NameSpace(sPath)
        oLink = oFolder.Items.Item(sFile).GetLink

        Return oLink.Path

    End Function


    Private Sub RealTimeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RealTimeToolStripMenuItem.Click
        For Each Process As Process In Process.GetProcessesByName(fistw)
            Process.PriorityClass = ProcessPriorityClass.RealTime 'oder .high usw.
        Next
    End Sub

    Private Sub HochToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HochToolStripMenuItem.Click
        For Each Process As Process In Process.GetProcessesByName(fistw)
            Process.PriorityClass = ProcessPriorityClass.High 'oder .high usw.
        Next
    End Sub

    Private Sub NormalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NormalToolStripMenuItem.Click
        For Each Process As Process In Process.GetProcessesByName(fistw)
            Process.PriorityClass = ProcessPriorityClass.Normal 'oder .high usw.
        Next
    End Sub
    Dim zs = 0
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        zs = zs + 1
        If zs = 255 Then
            zs = 0
            NotifyIcon1.ShowBalloonTip(250000)
        End If
    End Sub

    Private Sub EndeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EndeToolStripMenuItem.Click
        Me.Close()
    End Sub
End Class

